﻿using Fluffy.Library.DocumentContainer;
using Fluffy.Library.FileSources;
using System;
using System.IO;

namespace Fluffy.Torrent
{
	public class TorrentDocument : IDocumentContainer
	{
		private const string DefaultExtension = ".torrent";

		public string Title
		{
			get { return "Torrent"; }
		}

		public DocumentViewModelBase GenerateViewModel(IFile file)
		{
			TorrentDocumentModel model = new TorrentDocumentModel(file);
			TorrentDocumentViewModel viewModel = new TorrentDocumentViewModel(model);

			return viewModel;
		}

		public bool IsFileExtensionSupported(IFile file)
		{
			if (file is LinkFile)
			{
				return file.FilePath.StartsWith("magnet:", StringComparison.InvariantCultureIgnoreCase);
			}

			string extension = Path.GetExtension(file.FileName);
			return DefaultExtension.Equals(extension, StringComparison.InvariantCultureIgnoreCase);
		}
    }
}
